<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增仓库存储详情')" />
    <style>
        .fa-search{
            position: relative;
            top: -25px;
            left: 10px;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mallStoreDetail-add">
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">合同ID：</label>
                <div class="col-sm-8">
                    <input name="contractId" th:value="1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">入库单号：</label>
                <div class="col-sm-8">
                    <input name="storeDetailNo" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">仓库ID：</label>
                <div class="col-sm-8">
                    <input name="warehouseId" th:value="1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">入库类型：</label>
                <div class="col-sm-8">
                    <input name="type" th:value="1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group hidden">
                <label class="col-sm-3 control-label">详情Id：</label>
                <div class="col-sm-8">
                    <input name="orderDetailId" th:value="1" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">产品名称：</label>
                <div class="col-sm-8">
                    <input id="productId" name="productId" class="form-control hidden" type="text" value="">
                    <div class="input-group">
                        <input  type="text" class="form-control" id="suggest-demo-1">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-white dropdown-toggle" style="height: 31px" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">产品编码：</label>
                <div class="col-sm-8">
                    <input name="code" class="form-control" readonly="readonly" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">价格：</label>
                <div class="col-sm-8">
                    <input name="price" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">数量：</label>
                <div class="col-sm-8">
                    <input name="num" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">合作伙伴：</label>
                <div class="col-sm-8">
                    <input name="supplierId" class="form-control hidden" type="text">
                    <input name="supplierName" class="form-control" style="padding-left: 28px" type="text" onclick="selectOwner()">
                    <i class="fa fa-search"></i>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: bootstrap-typeahead-js" />
    <script th:inline="javascript">
        var prefix = ctx + "warehouse/mallStoreDetail"
        $("#form-mallStoreDetail-add").validate({
            focusCleanup: true
        });
        function selectOwner(){
            $.modal.open("选择合作伙伴",ctx + "partner/tenementInfo?type=1",1200,($(window).height() - 50),function (index, layero) {
                var rows = layero.find('iframe')[0].contentWindow.getSelectionRadio();
                debugger;
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $("input[name='supplierId']").val(rows[0].deptId);
                    $("input[name='supplierName']").val(rows[0].deptName);
                    $.modal.close(index);
                }
            });
        }
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-mallStoreDetail-add').serialize());
            }
        }


        $("#suggest-demo-1").bsSuggest({
                url: ctx + "product/product/selectMallStoreProductList?name=",
                allowNoKeyword: true,
                idField: "productId",
                keyField: "name",
                hideOnSelect: true,
                effectiveFields:['name','code','unit','price'],// 有效显示于列表中的字段，非有效字段都会过滤，默认全部有效。
                effectiveFieldsAlias: {"name":"产品名称","code":"产品编码","unit":"单位","price":"价格"},
                fnAdjustAjaxParam: function(keyword, opts) {
                    //.log("ajax 请求参数调整：", keyword, opts);
                    opts.url = opts.url + keyword;
                },
            })
            .on("onDataRequestSuccess", function(e, result) {
                console.log("onDataRequestSuccess: ", result);
            })
            .on("onSetSelectValue", function(e, keyword, data) {
                $("input[name='productId']").val(data.productId);
                $("input[name='code']").val(data.code);
                $("input[name='price']").val(data.price);
                //console.log("onSetSelectValue: ", keyword, data);
            })
            .on("onUnsetSelectValue", function() {
                console.log("onUnsetSelectValue");
            });

    </script>
</body>
</html>
